/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.approval.controller;

import com.icinfo.cloud.common.core.page.PageResponse;
import com.icinfo.cloud.provider.punish.approval.dto.ApprovalOpinionHisQueryDto;
import com.icinfo.cloud.provider.punish.approval.dto.AuditDetailDocumentQueryDto;
import com.icinfo.cloud.provider.punish.approval.dto.AuditQueryPageDto;
import com.icinfo.cloud.provider.punish.approval.service.ICaseApprovalCompleteRecordService;
import com.icinfo.cloud.provider.punish.approval.vo.*;
import com.icinfo.cloud.provider.punish.common.sign.vo.DocAttachmentsVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseAppendixRecordService;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;

/**
 * 描述: 案件文书审批完成记录 case_approval_complete_record 对应的Controller类.<br>
 * 已审批controller
 * @author 程亚运
 * @date 2022年02月15日
 */
@RestController
@RequestMapping("/audit")
public class CaseApprovalCompleteRecordController extends BaseController {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CaseApprovalCompleteRecordController.class);

    @Autowired
    private ICaseApprovalCompleteRecordService caseApprovalCompleteRecordService;

    @Autowired
    private ICaseAppendixRecordService caseAppendixRecordService;

    /**
     * 查询审批状态 对应案件数
     * @param
     * @return
     */
    @PostMapping("/getStageCaseNum")
    public Result<EachStageNumVo> getStageCaseNum(@RequestBody AuditQueryPageDto auditQueryPageDto){
        // 获得当前用户
        // 查询主表
        return Result.success("success",caseApprovalCompleteRecordService.getStageCaseNum(auditQueryPageDto));
    }

    /**
     * 查询已审批列表
     * @param auditQueryPageDto
     * @return
     */
    @PostMapping("/getOffAuditList")
    public Result<PageResponse<AuditInfoListVo>> getOffAuditList(@Validated @RequestBody AuditQueryPageDto auditQueryPageDto){
        // 查询 已审批表 根据用户id 查询 case_approval_complete_record
        return Result.success("success",new PageResponse<>(caseApprovalCompleteRecordService.getOffAuditList(auditQueryPageDto)));
    }

    /**
     * 描述: 工作台-查看更多，已审批列表对应案件数
     *
     * @param auditQueryPageDto
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/30
     */
    @PostMapping("/readStageNum")
    public Result<EachStageNumVo> readStageNum(@RequestBody AuditQueryPageDto auditQueryPageDto) {
        // 获得当前用户
        // 查询主表
        return Result.success("success", caseApprovalCompleteRecordService.getStageNum(auditQueryPageDto));
    }

    /**
     * 描述: 工作台-查看更多，已审批列表
     *
     * @param auditQueryPageDto
     * @return com.icinfo.framework.common.web.Result
     * @author zhanghongqiang
     * @Date 2022/8/30
     */
    @PostMapping("/readApprovedList")
    public Result<PageResponse<AuditInfoListVo>> readApprovedList(@Validated @RequestBody AuditQueryPageDto auditQueryPageDto) {
        // 查询 已审批表 根据用户id 查询 case_approval_complete_record
        return Result.success("success", new PageResponse<>(caseApprovalCompleteRecordService.getApprovedList(auditQueryPageDto)));
    }

    /**
     * =======================================================审批详情页面=======================================
     */

    /**
     * 查询审批详情页面审批文书基本信息
     *
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditDocDetail")
    public Result<AuditInfoVo> getAuditDocDetail(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){
        // 查询 案件基本信息 case_main_info
        // 查询 当前环节 案件审批表关联表 case_document_record 相同环节的审批表和审批表对应的文书
        // url 从文书服务取得
        return Result.success(caseApprovalCompleteRecordService.getAuditDocDetail(auditDetailDocumentQueryDto));
    }
    /**
     * 查询审批详情页面审批文书基本信息(裁执分离)
     *
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditDocDetailWithExecute")
    public Result<AuditInfoVo> getAuditDocDetailWithExecute(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){
        // 查询 案件基本信息 case_main_info
        // 查询 当前环节 案件审批表关联表 case_document_record 相同环节的审批表和审批表对应的文书
        // url 从文书服务取得
        return Result.success(caseApprovalCompleteRecordService.getAuditDocDetailWithExecute(auditDetailDocumentQueryDto));
    }

    /**
     * 查询审批详情页面审批文书对应附件
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/geDocRelationAttachments")
    public Result<List<DocAttachmentsVo>> geDocRelationAttachments(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){
        return Result.success("success",caseAppendixRecordService.getDocLinkAttachments(auditDetailDocumentQueryDto));
    }

    /**
     * 查询审批链日志
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditChain")
    public Result<List<AuditInfoChainLogVo>> getAuditChain(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto) throws ParseException {
        // 查询当前审批表关联流程的完整审批流
        // 查询 已审批表和待审批表 最后拼接 最后审批角色名
        List<AuditInfoChainLogVo> list =  caseApprovalCompleteRecordService.getAuditChain(auditDetailDocumentQueryDto);
        return Result.success("success",list);
    }


    /**
     * 查询审批链头部
     * @param auditDetailDocumentQueryDto
     * @return
     */
    @PostMapping("/getAuditChainTop")
    public Result<AuditInfoChainLogTopVo> getAuditChainTop(@Validated @RequestBody AuditDetailDocumentQueryDto auditDetailDocumentQueryDto){
        // 查询当前审批表关联流程的完整审批流
        // 查询 已审批表和待审批表 最后拼接 最后审批角色名
        return Result.success("success",caseApprovalCompleteRecordService.getAuditChainTop(auditDetailDocumentQueryDto));
    }
    /**
     * 查询历史审批内容
     * @author liyafeng
     * @date 2022/7/11
      * @param dto
     * @return {@link Result< List< String>>}
     */
    @PostMapping("/getApprovalOpinionHis")
    public Result<List<String>> getApprovalOpinionHis(@Validated @RequestBody ApprovalOpinionHisQueryDto dto){
        List<String> approvalOpinionHisList=caseApprovalCompleteRecordService.getApprovalOpinionHis(dto);
        return  Result.success("获取成功！",approvalOpinionHisList);
    }



}